package ch.nortgram.countdown_worldcup_2014.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import android.content.Context;

public final class DataLoader
	{
	private DataLoader()
		{
		};
		
	public static String loadData(final Context context, final String ressourceName) throws IOException
		{
		int resourceIdentifier = context.getApplicationContext().getResources().getIdentifier(ressourceName, "raw", context.getApplicationContext().getPackageName());
		if (resourceIdentifier != 0)
			{
			InputStream inputStream = context.getApplicationContext().getResources().openRawResource(resourceIdentifier);
			BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
			String line;
			StringBuffer data = new StringBuffer();
			while ((line = reader.readLine()) != null)
				{
				data.append(line);
				}
			reader.close();
			return data.toString();
			}
		return null;
		}
	}